package com.msh.automatic.android.control.script.util

import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import com.alibaba.fastjson2.JSONObject
import com.msh.automatic.android.control.script.service.ScriptAccessibilityService


object TaskApi {

    fun log(service: ScriptAccessibilityService, id:String, status: TaskLogStatus, message:String):Triple<String,String,JSONObject?>{

        // 切换到主线程显示Toast
        if(!message.isNullOrBlank()){
            Log.e("TASK",message)
            Handler(Looper.getMainLooper()).post {
                Toast.makeText(service, message, Toast.LENGTH_SHORT).show()
            }
        }
        return BaseApi.post("/d/task/log",
            mapOf(
                "id" to id,
                "status" to status,
                "message" to message,
            )
        )
    }
    fun debugAddress(ip:String,port:Int):Triple<String,String,JSONObject?>{
        return BaseApi.post("/d/device/debugAddress",
            mapOf(
                "vpnIp" to ip,
                "debugPort" to port
            )
        )
    }

}